﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;

namespace WebClient.style {
    public partial class index : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            

        }

        protected void Login_go_Click(object sender, EventArgs e) {
            //creating an instance of MCMS methods
            dom.proxy.service cms = new WebClient.dom.proxy.service();

            string clientIP = Request.ServerVariables["REMOTE_HOST"];
            string encrypted_pwd = SessionHandler.getMd5Hash(TB_Password.Text);
            //calling MCMS procedure
            dom.proxy.loginStatus status = cms.login(TB_Login.Text, TB_Password.Text, clientIP);
            login_status.Text = status.token.ResponseMessage;
            //if we sussessfully logged in, set coockies
            if (status.token.responseCode == 1) {
                HttpCookie CIM, AB, EM, CM, CI, SSID, uname;

                SSID = new HttpCookie("SSID");
                SSID.Value = status.sessionID.ToString();
                Response.Cookies.Add(SSID);

                CI = new HttpCookie("CI");
                CI.Value = "true";
                Response.Cookies.Add(CI);

                uname = new HttpCookie("Uname");
                uname.Value = status.username;
                Response.Cookies.Add(uname);

                if(status.cmsRoles[1] == WebClient.dom.proxy.cmsRoleGroup.CM){
                     CM = new HttpCookie("CM");
                     CM.Value = "1";
                     Response.Cookies.Add(CM);
                }
                if (status.cmsRoles[2] == WebClient.dom.proxy.cmsRoleGroup.AB){
                    AB = new HttpCookie("AB");
                    AB.Value = "1";
                    Response.Cookies.Add(AB);
                }

                if (status.cmsRoles[3] == WebClient.dom.proxy.cmsRoleGroup.CIM){
                    CIM = new HttpCookie("CIM");
                    CIM.Value = "1";
                    Response.Cookies.Add(CIM);
                }

                if (status.cmsRoles[4] == WebClient.dom.proxy.cmsRoleGroup.EM){
                    EM = new HttpCookie("EM");
                    EM.Value = "1";
                    Response.Cookies.Add(EM);
                }
            }
        }
    }
}
